package com.rome.hotel.data.utils;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证规则
 */
public class RegexUtils {


    public static void main(String[] args) {

    }
    /**
     * 账号和密码为字母或数字或符号任其组合
     */
    public static boolean testUsernameOrPassword(String username){
        Pattern pattern = Pattern.compile("^[a-zA-Z0-9!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]{1,30}$");
        Matcher matcher = pattern.matcher(username);
        boolean matches = matcher.matches();
        return  matches;
    }


    /**
     * 年龄大于0小于300且为整数
     */
    public static boolean testAge(String age){
        Pattern pattern = Pattern.compile("^(?:\\d{1,3}(?:\\,\\d{3})*|[1-9]\\d{0,2})$");
        Matcher matcher = pattern.matcher(age);
        boolean matches = matcher.matches();
        return  matches;
    }

    /**
     * 手机号以"1"开始，第二位是3、4、5、7或8，然后是9个数字（总计11位数字）的字符串
     */
    public static boolean testPhoneNumber(String phoneNumber){
        Pattern pattern = Pattern.compile("^1[34578][0-9]{9}$");
        Matcher matcher = pattern.matcher(phoneNumber);
        boolean matches = matcher.matches();
        return  matches;
    }



    /**
     * 验证邮箱，邮箱长度不能超过30位
     */
    public static boolean testEmail(String email){
        Pattern pattern = Pattern.compile("^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$");
        Matcher matcher = pattern.matcher(email);
        boolean matches = matcher.matches();
        return  matches;
    }

    /**
     * 验证金额
     */
    public static boolean testBalance(String balance){
        Pattern pattern = Pattern.compile("^[0-9]+(\\.[0-9]+)*$");
        Matcher matcher = pattern.matcher(balance);
        boolean matches = matcher.matches();
        return  matches;
    }
    /**
     * 验证只能是数字
     */
    public static boolean testNumber(String balance){
        Pattern pattern = Pattern.compile("^[0-9]+$");
        Matcher matcher = pattern.matcher(balance);
        boolean matches = matcher.matches();
        return  matches;
    }
    /**
     * 验证楼层名称
     */
    public static boolean testFloorName(String balance){
        Pattern pattern = Pattern.compile("^[\\u4e00-\\u9fa5a-zA-Z0-9]{0,50}$");
        Matcher matcher = pattern.matcher(balance);
        boolean matches = matcher.matches();
        return  matches;
    }
    /**
     * 内容1到300
     */
    public static boolean testStringNoThreeBai(String balance){
        Pattern pattern = Pattern.compile("^.{1,300}$");
        Matcher matcher = pattern.matcher(balance);
        boolean matches = matcher.matches();
        return  matches;
    }
    /**
     * 内容1到50
     */
    public static boolean testStringNoWuShi(String balance){
        Pattern pattern = Pattern.compile("^.{1,50}$");
        Matcher matcher = pattern.matcher(balance);
        boolean matches = matcher.matches();
        return  matches;
    }
    /**
     * 身份证
     */
    public static boolean testIdCards(String balance){
        boolean matches=false;
        if(balance.length()==18){
            Pattern pattern18 = Pattern.compile( "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");
            Matcher matcher = pattern18.matcher(balance);
            matches= matcher.matches();
        }else if(balance.length()==15){
            Pattern pattern15 = Pattern.compile( "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$");
            Matcher matcher = pattern15.matcher(balance);
            matches= matcher.matches();
        }
        return  matches;
    }
}
